﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedisLogQueueTest.CommonFunc
{
    /// <summary>
    /// 日志单例工厂
    /// </summary>
    public class LoggerFactory
    {
        public static string CommonQueueName = "DisSunQueue";
        private static LoggerFunc log;
        private static object logKey = new object();
        public static LoggerFunc CreateLoggerInstance()
        {
            if (log != null)
            {
                return log;
            }

            lock (logKey)
            {
                if (log == null)
                {
                    string log4NetPath = AppDomain.CurrentDomain.BaseDirectory + "Config\\log4net.config";
                    log = new LoggerFunc();
                    log.logCfg = new FileInfo(log4NetPath);
                    log.errorLogger = log4net.LogManager.GetLogger("MyError");
                    log.QueueName = CommonQueueName;//存储在Redis中的键名
                    log4net.Config.XmlConfigurator.ConfigureAndWatch(log.logCfg);    //加载日志配置文件S                
                }
            }

            return log;
        }
    }
}
